package com.android.nfctouch.ui.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;

import com.android.baselibrary.event.Event_Token_Failure;
import com.android.baselibrary.ui.AbsBaseActivity;
import com.android.baselibrary.view.Comm_HeadView;
import com.android.nfctouch.R;
import com.android.nfctouch.manager.UserManager;
import com.gyf.immersionbar.ImmersionBar;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public abstract class BaseActivity extends AbsBaseActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Comm_HeadView comm_title = findViewById(R.id.comm_title);
        if (comm_title != null) {
            comm_title.setLeftClickFinish(this);
        }
        //是否沉浸式
        if (isImmersion()) {
            if (getImmersionTitleBar() != null) {
                ImmersionBar.with(this).titleBar(getImmersionTitleBar());
            }
            ImmersionBar.with(this).statusBarDarkFont(true).navigationBarDarkIcon(true).init();
        }
    }

    protected boolean isImmersion() {
        return true;
    }

    @Override
    protected boolean isRegistEventbus() {
        return true;
    }

    protected View getImmersionTitleBar() {
        Comm_HeadView comm_title = findViewById(R.id.comm_title);
        return comm_title;
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(Event_Token_Failure event) {
        if (this.getClass().getSimpleName().equals(MainActivity.class.getSimpleName())||
                this.getClass().getSimpleName().equals(LoadingActivity.class.getSimpleName())) {
            UserManager.logout((Activity) mContext);
            UserManager.toLogin(this);
            finish();
        } else if(!this.getClass().getSimpleName().equals(LoginActivity.class.getSimpleName())){
            finish();
        }
    }


}
